package com.rybbaby.tss.platform.sysMenuPermissions.entity;

import java.io.Serializable;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;

import com.rybbaby.tss.core.utils.StringUtils;
import com.rybbaby.tss.platform.sysAdminUser.entity.SysAdminUser;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * @description 菜单权限
 * 
 * @author 谢进伟
 * 
 * @createDate 2016-08-19 上午11:36:25
 */
@Entity
@Table(name = "sys_menu_permissions")
@DynamicUpdate(true)
@DynamicInsert(true)
public class SysMenuPermissions implements Cloneable , Serializable , Comparable<SysMenuPermissions> {
	
	private static final long serialVersionUID = 355090499461173L;
	
	/** 主键 **/
	private String id;
	/** 父菜单Id **/
	private String pId;
	/** 名称 **/
	private String name;
	/** 图标 **/
	private String icon;
	/** 链接 **/
	private String url;
	/** 权重 **/
	private Integer weight;
	/** 是否禁用 **/
	private Boolean isForbidden;
	/** 创建时间 **/
	private java.sql.Timestamp createTime;
	/** 创建人Id **/
	private String createUserId;
	/** 操作权限标识 **/
	private String handlePermissionIdentifier;
	/** 版本 **/
	private Integer version;
	/** 父菜单Id **/
	private SysMenuPermissions parent;
	/** 管理员Id **/
	private SysAdminUser adminUser;
	/** 子菜单 **/
	private Set<SysMenuPermissions> childrens = new TreeSet<SysMenuPermissions>();
	
	/**
	 * 方法: 取得管理员Id
	 *
	 * @return SysAdminUser 管理员Id
	 */
	@JsonIgnore
	@JoinColumn(name = "createUserId" , insertable = false , updatable = false)
	@ManyToOne(fetch = FetchType.LAZY , targetEntity = SysAdminUser.class)
	public SysAdminUser getAdminUser() {
		return this.adminUser;
	}
	
	/**
	 * 方法: 设置管理员Id
	 *
	 * @param adminUser
	 *            管理员Id
	 */
	public void setAdminUser(SysAdminUser adminUser) {
		this.adminUser = adminUser;
	}
	
	/**
	 * 方法: 取得父菜单Id
	 *
	 * @return SysMenuPermissions 父菜单Id
	 */
	@JsonIgnore
	@JoinColumn(name = "pId" , insertable = false , updatable = false)
	@ManyToOne(fetch = FetchType.LAZY , targetEntity = SysMenuPermissions.class)
	public SysMenuPermissions getParent() {
		return this.parent;
	}
	
	/**
	 * 方法: 设置父菜单Id
	 *
	 * @param parent
	 *            父菜单Id
	 */
	public void setParent(SysMenuPermissions parent) {
		this.parent = parent;
	}
	
	/**
	 * 方法: 取得主键
	 *
	 * @return java.lang.String 主键
	 */
	@Id
	@GeneratedValue(generator = "sys_menu_permissionsIDGenerator" , strategy = GenerationType.AUTO)
	@GenericGenerator(name = "sys_menu_permissionsIDGenerator" , strategy = "uuid")
	@Column(name = "id" , nullable = false , length = 32)
	public String getId() {
		return this.id;
	}
	
	/**
	 * 方法: 设置主键
	 *
	 * @param id
	 *            主键
	 */
	public void setId(String id) {
		this.id = id;
	}
	
	/**
	 * 方法: 取得父菜单Id
	 *
	 * @return java.lang.String 父菜单Id
	 */
	@Column(name = "pId" , nullable = true , length = 32)
	public String getpId() {
		return this.pId;
	}
	
	/**
	 * 方法: 设置父菜单Id
	 *
	 * @param pId
	 *            父菜单Id
	 */
	public void setpId(String pId) {
		this.pId = StringUtils.isBlank(pId) ? null : pId;
	}
	
	/**
	 * 方法: 取得名称
	 *
	 * @return java.lang.String 名称
	 */
	@Column(name = "name" , nullable = true , length = 24)
	public String getName() {
		return this.name;
	}
	
	/**
	 * 方法: 设置名称
	 *
	 * @param name
	 *            名称
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * 方法: 取得图标
	 *
	 * @return java.lang.String 图标
	 */
	@Column(name = "icon" , nullable = true , length = 100)
	public String getIcon() {
		return this.icon;
	}
	
	/**
	 * 方法: 设置图标
	 *
	 * @param icon
	 *            图标
	 */
	public void setIcon(String icon) {
		this.icon = icon;
	}
	
	/**
	 * 方法: 取得链接
	 *
	 * @return java.lang.String 链接
	 */
	@Column(name = "url" , nullable = true , length = 100)
	public String getUrl() {
		return this.url;
	}
	
	/**
	 * 方法: 设置链接
	 *
	 * @param url
	 *            链接
	 */
	public void setUrl(String url) {
		this.url = url;
	}
	
	/**
	 * 方法: 取得权重
	 *
	 * @return java.lang.Integer 权重
	 */
	@Column(name = "weight" , nullable = true , length = 11)
	public Integer getWeight() {
		return this.weight;
	}
	
	/**
	 * 方法: 设置权重
	 *
	 * @param weight
	 *            权重
	 */
	public void setWeight(Integer weight) {
		this.weight = weight;
	}
	
	/**
	 * 方法: 取得是否禁用
	 *
	 * @return java.lang.Boolean 是否禁用
	 */
	@Column(name = "isForbidden" , nullable = true , length = 1)
	public Boolean getIsForbidden() {
		return this.isForbidden;
	}
	
	/**
	 * 方法: 设置是否禁用
	 *
	 * @param isForbidden
	 *            是否禁用
	 */
	public void setIsForbidden(Boolean isForbidden) {
		this.isForbidden = isForbidden;
	}
	
	/**
	 * 方法: 取得创建时间
	 *
	 * @return java.sql.Timestamp 创建时间
	 */
	@Column(name = "createTime" , nullable = true , length = 19)
	public java.sql.Timestamp getCreateTime() {
		return this.createTime;
	}
	
	/**
	 * 方法: 设置创建时间
	 *
	 * @param createTime
	 *            创建时间
	 */
	public void setCreateTime(java.sql.Timestamp createTime) {
		this.createTime = createTime;
	}
	
	/**
	 * 方法: 取得创建人Id
	 *
	 * @return java.lang.String 创建人Id
	 */
	@Column(name = "createUserId" , nullable = true , length = 32)
	public String getCreateUserId() {
		return this.createUserId;
	}
	
	/**
	 * 方法: 设置创建人Id
	 *
	 * @param createUserId
	 *            创建人Id
	 */
	public void setCreateUserId(String createUserId) {
		this.createUserId = createUserId;
	}
	
	/**
	 * 方法: 取得操作权限标识
	 *
	 * @return java.lang.String 操作权限标识
	 */
	@Column(name = "handlePermissionIdentifier" , nullable = true , length = 255)
	public String getHandlePermissionIdentifier() {
		return handlePermissionIdentifier;
	}
	
	/**
	 * 方法: 设置操作权限标识
	 *
	 * @param createUserId
	 *            操作权限标识
	 */
	public void setHandlePermissionIdentifier(String handlePermissionIdentifier) {
		this.handlePermissionIdentifier = handlePermissionIdentifier;
	}
	
	/**
	 * 方法: 取得版本
	 *
	 * @return java.lang.Integer 版本
	 */
	@Version
	@Column(name = "version" , nullable = true , length = 11)
	public Integer getVersion() {
		return this.version;
	}
	
	/**
	 * 方法: 设置版本
	 *
	 * @param version
	 *            版本
	 */
	public void setVersion(Integer version) {
		this.version = version;
	}
	
	@Transient
	public Set<SysMenuPermissions> getChildrens() {
		return childrens;
	}
	
	public void setChildrens(Set<SysMenuPermissions> childrens) {
		this.childrens = childrens;
	}
	
	@Override
	public int compareTo(SysMenuPermissions o) {
		return this.getWeight().compareTo(o.getWeight());
	}
	
	@Override
	public boolean equals(Object o) {
		if(o instanceof SysMenuPermissions) {
			return this.getId().equals(((SysMenuPermissions)o).getId());
		} else {
			return false;
		}
	}
	
	@Override
	public SysMenuPermissions clone() throws CloneNotSupportedException {
		return (SysMenuPermissions)super.clone();
	}
}